package com.hptpd.questionnairesurvey.vo;

import com.hptpd.questionnairesurvey.assets.Constant;
import com.hptpd.questionnairesurvey.domain.Choice;
import com.hptpd.questionnairesurvey.domain.question.BaseQuestion;
import com.hptpd.questionnairesurvey.domain.question.FillsUpQuestion;
import com.hptpd.questionnairesurvey.domain.question.SingleChoiceQuestion;
import com.hptpd.questionnairesurvey.utils.AbstractMyBeanUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Data
public class QuestionVo{

    private String id;

    private String topic;

    private Integer sort;

    private String type;

    private List<ChoiceVo> choiceVos;

    private boolean checked = true;

    /**
     * 维度名称
     */
    private String dimension;
    /**
     * 维度暂时生成的标识
     */
    private String dimensionTempTag;



    public static QuestionVo toVo(BaseQuestion question, QuestionnaireVo questionnaireVo, DimensionalityVo dimensionalityVo) {
        QuestionVo questionVo = new QuestionVo();
        AbstractMyBeanUtils.copyProperties(question, questionVo);
        if (question instanceof FillsUpQuestion) {
            questionVo.setType(Constant.QUESTION_TYPE_FILL);
        } else {
            questionVo.setType(Constant.QUESTION_TYPE_SINGLE);
            questionVo.setChoiceVos(ChoiceVo.toVos(question.getChoices()));
        }
        if (null != dimensionalityVo) {
            questionVo.setDimension(dimensionalityVo.getName());
        } else {
            questionVo.setChecked(false);
        }
        questionnaireVo.getQuestions().add(questionVo);
        return questionVo;
    }

    public static List<QuestionVo> toVos(List<BaseQuestion> questions, QuestionnaireVo questionnaireVo, DimensionalityVo dimensionalityVo) {
        List<QuestionVo> questionVos = new ArrayList<>();
        for (BaseQuestion baseQuestion :
                questions) {
            questionVos.add(toVo(baseQuestion, questionnaireVo, dimensionalityVo));
        }
        return questionVos;
    }
}
